<!DOCTYPE html>
<html>

<head>
    <!-- 页面meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>商品管理</title>
    <!-- Tell the browser to be responsive to screen width -->
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
    <link rel="stylesheet" href="../plugins/bootstrap/css/bootstrap.min.css">
    <link rel="stylesheet" href="../plugins/adminLTE/css/AdminLTE.css">
    <link rel="stylesheet" href="../plugins/adminLTE/css/skins/_all-skins.min.css">
    <link rel="stylesheet" href="../css/style.css">
	<script src="../plugins/jQuery/jquery-2.2.3.min.js"></script>
    <script src="../plugins/bootstrap/js/bootstrap.min.js"></script>
    <script type="text/javascript" src="/js/toastr/toastr.min.js"></script>
    <link rel="stylesheet" type="text/css" href="/js/toastr/toastr.css">

</head>

<body class="hold-transition skin-red sidebar-mini" >
  <!-- .box-body -->
                
                    <div class="box-header with-border">
                        <h3 class="box-title">商品审核</h3>
                    </div>

                    <div class="box-body">

                        <!-- 数据表格 -->
                        <div class="table-box">

                            <!--工具栏-->
                            <div class="pull-left">
                                <div class="form-group form-inline">
                                    <div class="btn-group">
                                        <button type="button" class="btn btn-default" title="删除" onclick="deleteInfo()"><i class="fa fa-trash-o"></i> 删除</button>
                                        <button type="button" class="btn btn-default" title="审核通过" onclick="pass()"><i class="fa fa-check"></i> 审核通过</button>
                                        <button type="button" class="btn btn-default" title="驳回" onclick="noPass()"><i class="fa fa-ban"></i> 驳回</button>
                                        <button type="button" class="btn btn-default" title="刷新" onclick="refresh()" ><i class="fa fa-refresh"></i> 刷新</button>
                                    </div>
                                </div>
                            </div>
                            <div class="box-tools pull-right">
                                <div class="has-feedback">
                                    商品名称：<input type="text" name="goodsName" id="goodsName">
									<button class="btn btn-default"  onclick="show()">查询</button>
                                </div>
                            </div>
                            <!--工具栏/-->

			                  <!--数据列表-->
			                  <table id="dataList" class="table table-bordered table-striped table-hover dataTable">
			                      <thead>
			                          <tr>
			                              <th class="" style="padding-right:0px">
			                                  <input id="selall" type="checkbox" class="icheckbox_square-blue">
			                              </th> 
										  <th class="sorting_asc">商品ID</th>
									      <th class="sorting">商品名称</th>
									      <th class="sorting">商品价格</th>
									      <th class="sorting">一级分类</th>
									      <th class="sorting">二级分类</th>
									      <th class="sorting">三级分类</th>
									      <th class="sorting">状态</th>									     						
					                      <th class="text-center">操作</th>
			                          </tr>
			                      </thead>
								  <script>
									  $(function (){
										 showTbItemCat();
									  })
                                        var a;
                                      function showTbItemCat() {
                                          $.ajax({
                                              url: "/tbGoods/showItem",
                                              type: "get", //请求方式 get post 默认get
                                              dataType: "json", //返回值类型 html json text xml
                                              async: true,//true代表异步请求 false代表同步请求
                                              success: function (result) {//成功回调函数
                                                  var page = result.data;
                                                  a = page;
                                                  show();
                                              },
                                              error: function (i) {//发生错误回调函数
                                                  alert("异常错误")
                                              }

                                          })
                                      }
									  function show() {
										  $.ajax({
											  url: "/tbGoods/getGood",
                                              data:{ goodsName: $("#goodsName").val(), pageNum: $("#pageNumber").val(), pageSize: $("#pageSize").val()},
											  type: "get", //请求方式 get post 默认get
											  dataType: "json", //返回值类型 html json text xml
											  async: true,//true代表异步请求 false代表同步请求
											  success: function (result) {//成功回调函数
												  var page = result.data.rows;
												  var div = "";
												  for (var i = 0; i < page.length; i++) {
													  div += '<tr> <td><input type="checkbox" name="check" value="' + page[i].id + '"></td>';
														  div +='<td>' + page[i].id + '</td>';
														  div +='<td>' + page[i].goodsName +'</td>';
														  div +='<td>' + page[i].price+ '</td>';
														  var count =0;
                                                      for (var j = 0; j < a.length; j++) {
                                                          if (a[j].id == page[i].category1Id){
                                                              div +='<td>' + a[j].name + '</td>';
                                                              count = 1;
                                                          }

                                                      }
                                                      if(count == 0){
                                                          div +='<td>此数据为空</td>';
                                                      }
                                                      var count1 = 0;
                                                      for (var j = 0; j < a.length; j++) {
                                                          if (a[j].id == page[i].category2Id){
                                                              div +='<td>' + a[j].name + '</td>';
                                                              count1 = 1;
                                                          }

                                                      }
                                                      if(count1 == 0){
                                                          div +='<td>此数据为空</td>';
                                                      }
                                                      count2 = 0;
                                                      for (var j = 0; j < a.length; j++) {
                                                          if (a[j].id == page[i].category3Id){
                                                              div +='<td>' + a[j].name + '</td>';
                                                              count2 = 1;
                                                          }

                                                      }
                                                      if(count2 == 0){
                                                          div +='<td>此数据为空</td>';
                                                      }
                                                         if(page[i].auditStatus == 0){
                                                             div +='<td><span>未审核</span></td>';
                                                         }else if(page[i].auditStatus == 1){
                                                             div +='<td><span>审核通过</span></td>';
                                                         }else{
                                                             div +='<td><span>审核未通过</span></td>';
                                                         }
                                                       div +='<td className="text-center"><button type="button" className="btn bg-olive btn-xs">详情</button></td></tr>';
												  }
												  $("#html").html(div);
												  install_page(result.data)
											  },
											  error: function (i) {//发生错误回调函数
												  alert("异常错误")
											  }

										  })
									  }

                                      function deleteInfo() {
                                          var rows = $("[name=check]:checked");
                                          var ids = [];
                                          $(rows).each(function (i, e) {
                                              ids[i] = e.value;
                                          })
                                          if (ids.length == 0) {
                                              toastr.success("请选择要删除的数据");
                                              return;
                                          }
                                          $.ajax({
                                              url: "/tbGoods/deleteInfo?ids=" + ids,
                                              type: "post", //请求方式 get post 默认get
                                              dataType: "json", //返回值类型 html json text xml
                                              async: true,//true代表异步请求 false代表同步请求
                                              success: function (result) {//成功回调函数
                                                  if (result.code == 10000) {
                                                      toastr.success("删除成功");
                                                      setTimeout("refresh()", 1000);//3秒后执行refresh()
                                                  } else {
                                                      toastr.error("删除失败");
                                                  }

                                              },
                                              error: function (i) {//发生错误回调函数
                                                  alert("异常错误")
                                              }
                                          })
                                      }
                                      function pass() {
                                          var rows = $("[name=check]:checked");
                                          var ids = [];
                                          $(rows).each(function (i, e) {
                                              ids[i] = e.value;
                                          })
                                          if (ids.length == 0) {
                                              toastr.success("请选择要删除的数据");
                                              return;
                                          }
                                          $.ajax({
                                              url: "/tbGoods/pass?ids=" + ids,
                                              type: "post", //请求方式 get post 默认get
                                              dataType: "json", //返回值类型 html json text xml
                                              async: true,//true代表异步请求 false代表同步请求
                                              success: function (result) {//成功回调函数
                                                  if (result.code == 10000) {
                                                      toastr.success("审核通过操作成功");
                                                      setTimeout("refresh()", 1000);//3秒后执行refresh()
                                                  } else {
                                                      toastr.error("审核未通过");
                                                  }

                                              },
                                              error: function (i) {//发生错误回调函数
                                                  alert("异常错误")
                                              }
                                          })
                                      }
                                      function noPass() {
                                          var rows = $("[name=check]:checked");
                                          var ids = [];
                                          $(rows).each(function (i, e) {
                                              ids[i] = e.value;
                                          })
                                          if (ids.length == 0) {
                                              toastr.success("请选择要删除的数据");
                                              return;
                                          }
                                          $.ajax({
                                              url: "/tbGoods/noPass?ids=" + ids,
                                              type: "post", //请求方式 get post 默认get
                                              dataType: "json", //返回值类型 html json text xml
                                              async: true,//true代表异步请求 false代表同步请求
                                              success: function (result) {//成功回调函数
                                                  if (result.code == 10000) {
                                                      toastr.success("已取消审核通过");
                                                      setTimeout("refresh()", 1000);//3秒后执行refresh()

                                                  }else {
                                                      toastr.error("取消审核通过失败");
                                                  }

                                              },
                                              error: function (i) {//发生错误回调函数
                                                  alert("异常错误")
                                              }
                                          })
                                      }


                                          function refresh() {
                                          window.location.reload();
                                      }
								  </script>
			                      <tbody id="html">

			                      </tbody>
			                  </table>
                            <div th:insert="common/page.html"></div>
			                  <!--数据列表/-->                        
							  
							 
                        </div>
                        <!-- 数据表格 /-->
                        
                        
                     </div>
                    <!-- /.box-body -->
        
</body>

</html>